import { IPSDataEntity } from '../ipsdata-entity';
import { IPSDEActionParam } from './ipsdeaction-param';
import { IPSDEField } from '../defield/ipsdefield';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDEActionParamImpl extends PSModelObjectImpl implements IPSDEActionParam {
  get codeName(): string {
    return this.M.codeName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  get orderValue(): number {
    return this.M.orderValue != null ? this.M.orderValue : 99999;
  }

  protected psdefield: IPSDEField | null = null;

  getPSDEField(): IPSDEField | null {
    if (this.psdefield != null) return this.psdefield;
    const value = this.M.getPSDEField;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.psdefield = ipsdataentity.findPSDEField(value);
    }
    return this.psdefield;
  }

  get psDEField(): IPSDEField | null {
    return this.getPSDEField();
  }

  getPSDEFieldMust(): IPSDEField {
    const value = this.getPSDEField();
    if (value == null) {
      throw new Error('未指定参数实体属性');
    }
    return value;
  }

  get paramDesc(): string {
    return this.M.paramDesc;
  }

  get paramTag(): string {
    return this.M.paramTag;
  }

  get paramTag2(): string {
    return this.M.paramTag2;
  }

  get stdDataType(): 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 {
    return this.M.stdDataType;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get value(): string {
    return this.M.value;
  }

  get valueType():
    | 'INPUTVALUE'
    | 'NONEVALUE'
    | 'PARAM'
    | 'VALUE'
    | 'NULLVALUE'
    | 'SESSION'
    | 'APPLICATION'
    | 'UNIQUEID'
    | 'CONTEXT'
    | 'OPERATOR'
    | 'OPERATORNAME'
    | 'CURTIME'
    | 'APPDATA'
    | 'EXPRESSION'
    | 'USER'
    | 'USER2'
    | 'USER3'
    | 'USER4' {
    return this.M.valueType;
  }

  get allowEmpty(): boolean {
    return this.M.allowEmpty != null ? this.M.allowEmpty : true;
  }

  get array(): boolean {
    return this.M.array != null ? this.M.array : false;
  }

  get cls(): string {
    return 'PSDEActionParamImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'IPSModelSortable' || cls == 'dataentity.action.IPSDEActionParam') return true;
    return super.instanceof(cls);
  }
}
